package com.zbf.adarenbug;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: LCG
 * @Date: 2021-11-18 10:25:01
 * @description:
 **/
public class MyDataListener extends AnalysisEventListener<EnData> {

    private List<Object> list=new ArrayList<Object>();

    @Override
    public void invoke(EnData enData, AnalysisContext analysisContext) {
        if(enData.getVideoId()!=null){
            Map<String, String> headers=new HashMap<>();
            headers.put("Content-Type", "application/json");
            Map<String,String> mmm=new HashMap<>();
            mmm.put("videoId",enData.getVideoId());
            try {
                //  http://47.94.152.49:7000/api/syncDarenInfoById
                String body = Jsoup.connect("").ignoreContentType(true).headers(headers)
                        .requestBody(JSON.toJSONString(mmm)).timeout(60000).post().body().text();
                if(JSON.parseObject(body).getInteger("code")==500){
                   list.add(enData);
                }
                System.out.println(enData.getVideoId()+"====="+body);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println(JSON.toJSONString(list));
    }
}
